package com.sky.controller.admin;

import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: HuoXu
 * @Date: 2023/08/17/16:18
 * @Description: 快乐跳跳虎
 */
@RestController("adminShopController")
@Slf4j
@RequestMapping("/admin/shop")
public class ShopController {

    //将状态设置为常量
    private static final String key="SHOP_STATUS";
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 设置店铺的营业状态
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    public Result setShopStatus(@PathVariable Integer status) {
        log.info("设置店铺营业状态为,{}",status==1 ? "营业中":"打烊中");
        redisTemplate.opsForValue().set(key,status);
        return Result.success();
    }

    /**
     * 获取店铺的营业状态
     * @return
     */
    @GetMapping("/status")
    public Result<Integer> getShopStatus(){
        Integer shop_status = (Integer) redisTemplate.opsForValue().get(key);
        log.info("获取营业状态为,{}",shop_status==1 ? "营业中":"打烊中");
        return Result.success(shop_status);
    }
}
